package @{crud.properties.base_package}.@{crud.properties.model}.service.impl;


import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.plugins.Page;
import cn.lvji.core.vo.Grid;
import cn.lvji.core.vo.Response;

import @{crud.properties.base_package}.@{crud.properties.model}.entity.@{crud.table.className};
import @{crud.properties.base_package}.@{crud.properties.model}.dao.@{crud.table.className}Mapper;
import @{crud.properties.base_package}.@{crud.properties.model}.service.@{crud.table.className}Service;

/**
 * 
 * @{crud.table.remarks}:业务接口实现类
 * 
 * @author generator
 */
@Service
@Transactional
public class @{crud.table.className}ServiceImpl implements @{crud.table.className}Service {
    private static final Logger logger = LoggerFactory.getLogger(@{crud.table.className}ServiceImpl.class);
    
    private @{crud.table.className}Mapper @{strutils.toLowerCaseFirst(crud.table.className)}Mapper;
    
    @Autowired
    public @{crud.table.className}ServiceImpl(@{crud.table.className}Mapper @{strutils.toLowerCaseFirst(crud.table.className)}Mapper){
        this.@{strutils.toLowerCaseFirst(crud.table.className)}Mapper = @{strutils.toLowerCaseFirst(crud.table.className)}Mapper;
    }
    
    @Override
    public Response<Void> save(@{crud.table.className} @{strutils.toLowerCaseFirst(crud.table.className)}){
        if(logger.isDebugEnabled()) {
            logger.debug("add @{crud.table.className} ,the params is {}",@{strutils.toLowerCaseFirst(crud.table.className)});
        }
        @{strutils.toLowerCaseFirst(crud.table.className)}Mapper.insert(@{strutils.toLowerCaseFirst(crud.table.className)});
        return Response.SUCCESS;
    }
    
    @Override
    public @{crud.table.className} get(Long id){
        if(logger.isDebugEnabled()) {
            logger.debug("query @{crud.table.className} by {}",id);
        }
        return @{strutils.toLowerCaseFirst(crud.table.className)}Mapper.selectById(id);
    }
    
    @Override
    public Response<Grid<@{crud.table.className}>> list(Page<@{crud.table.className}> page, @{crud.table.className} @{strutils.toLowerCaseFirst(crud.table.className)}){
        if(logger.isDebugEnabled()) {
            logger.debug("queryPage @{crud.table.className} ,the entity is {},the page is {}",@{strutils.toLowerCaseFirst(crud.table.className)},page);
        }
        Response<Grid<@{crud.table.className}>> res = new Response<>();
        List<@{crud.table.className}> result = @{strutils.toLowerCaseFirst(crud.table.className)}Mapper.get@{crud.table.className}Page(page,
            @{strutils.toLowerCaseFirst(crud.table.className)});
        Grid<@{crud.table.className}> grid = new Grid<>();
        grid.setTotal(page.getTotal());
        grid.setPages(page.getPages());
        grid.setList(result);
        res.setData(grid);
        return res;
    }
    
    
    @Override
    public Response<Void> update(@{crud.table.className} @{strutils.toLowerCaseFirst(crud.table.className)}){
        if(logger.isDebugEnabled()) {
            logger.debug("update @{crud.table.className} ,the entity is {}",@{strutils.toLowerCaseFirst(crud.table.className)});
        }
        @{strutils.toLowerCaseFirst(crud.table.className)}Mapper.updateById(@{strutils.toLowerCaseFirst(crud.table.className)});
        return Response.SUCCESS;
    }
    
    @Override
    public Response<Void> delete(Long id){
        if(logger.isDebugEnabled()) {
            logger.debug("delete @{crud.table.className} by id {}",id);
        }
        @{strutils.toLowerCaseFirst(crud.table.className)}Mapper.deleteById(id);
        return Response.SUCCESS;
    }
    
}